<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="选择会员"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-space >
            <a-input-search
              v-model="value"
              placeholder="请输入手机号或者会员卡号"
              enter-button
              @change="handleChange"
              @search="onSearch"
            />
            <a-input v-show="false" v-decorator="['memId']"/>
            <a-button type="primary" v-if="JSON.stringify(this.memberDetail) !== '{}'" @click="cancel">取消</a-button>
          </a-space>
        </a-form-item>
        <a-form-item
          label="会员详情"
          v-if="JSON.stringify(this.memberDetail) !== '{}'"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-descriptions>
            <a-descriptions-item label="会员名称" :span="3">{{ memberDetail.name }}</a-descriptions-item>
            <a-descriptions-item label="会员电话" :span="3">{{ memberDetail.phone }}</a-descriptions-item>
            <a-descriptions-item label="会员卡号" :span="3">{{ memberDetail.cardNo }}</a-descriptions-item>
            <a-descriptions-item label="会员积分" :span="3">{{ memberDetail.hisBigintegral }}</a-descriptions-item>
          </a-descriptions>
        </a-form-item>
        <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
          <a-space>
            <a-button htmlType="submit" type="primary" :loading="loading" icon="check">确认赠送</a-button>
          </a-space>
        </a-form-item>
      </a-form>
      <div>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import {getMemberByNumberUsingGET,giveIntegralUsingPOST} from '@/api/api/huiyuanguanli.ts'
export default {
  name: 'MemberPresentScoreActivity',
  data() {
    return {
      form: this.$form.createForm(this),
      visible: false,
      value:'',
      confirmLoading: false,
      loading: false,
      viploading: false,
      addmdl: null,
      current: 1,
      keyword: '',
      info: {},
      memberDetail:{},
      kindOption: [],
      userOption: [],
      memberOption: [],
    }
  },
  methods: {
    cancel(){
      this.memberDetail = {}
      this.form.setFieldsValue({memId:''})
    },
    onSearch(value) {
      if(!value){
        this.$message.warn('请输入正确的手机号或会员卡号')
      }
      this.handleMember(value)
    },
    handleChange(e) {
      this.value = e.target.value
    },
    handleMember(params) {
      getMemberByNumberUsingGET({
        number: params,
      })
        .then((res) => {
          if(res.data){
            this.memberDetail = res.data
            this.form.setFieldsValue({memId:res.data.id})
          }else{
            this.memberDetail = {}
          }
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleSubmit(e) {
      e.preventDefault()
      this.loading = true
      this.form.validateFields((err, values) => {
        if (!err) {
          giveIntegralUsingPOST({ ...values, actId: this.$route.params.id })
            .then((res) => {
              this.$message.success('操作成功')
              this.$router.back()
              this.loading = false
            })
            .catch((error) => {
              this.loading = false
              this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
            })
        }
      })
    },
  },
}
</script>
